#!/usr/bin/env python
#
#   Copyright (C) 2006 Jonathan Saggau                                     
#   saggau@gmail.com                                                       
#                                                                          
#   This program is free software; you can redistribute it and/or modify  
#   it under the terms of the GNU General Public License as published by  
#   the Free Software Foundation; either version 2 of the License, or     
#   (at your option) any later version.                                    
#                                                                          
#   This program is distributed in the hope that it will be useful,        
#   but WITHOUT ANY WARRANTY; without even the implied warranty of        
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         
#   GNU General Public License for more details.                          
#                                                                          
#   You should have received a copy of the GNU General Public License     
#   along with this program; if not, write to the                         
#   Free Software Foundation, Inc.,                                        
#   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.  
#

from model import Model
from supyrconductor.synthdef import Synthdef
import deftxt

class Buildtxt(Model, Synthdef):
    """models the text part of the synthdef"""
    
    def __init__(self):
        Model.__init__(self, nodeID=1, bufferID=1)
        Synthdef.__init__(self, name=self.synthName(), body=deftxt.body,
                          generic=deftxt.generic)
        
    def _replacements(self):
        """generate the string replacements, from of dictionary"""
        outLine = deftxt.outlines[self.channels]
        bufPointerLine = deftxt.synths[self.synthType]
        envLine = deftxt.envs[self.envType]
        self.name = self.synthName() #kludge
        replacements = {"NUMBER_OF_OVERLAPS":self.overlap, 
                        "OUT_LINE":outLine,
                        "BUFPOINTER_LINE":bufPointerLine,
                        "ENV_LINE":envLine}
        # Default to mono, static, percussive
        return replacements

    def getString(self, args=None, replacements=None):
        """Default to the args and replacements from self, but allow args
           and replacements to be passed in as in Synthdef.getString()"""
        out = Synthdef.getString(self, self._synthargs(), self._replacements())
        return out
        # can't remember the syntax for super.methods() that return values...
    